
var path = require('path')
const express = require('express')
const app = express()
var http = require('http').Server(app)
var bodyParser = require('body-parser')
var config = require('./config')

const merchantRouter = require('./router/MerchantRouter')

app.use(express.static(path.join(__dirname, 'static')))
app.use(bodyParser())

// merchant
app.use('/api/merchant', merchantRouter)

// 所有没有定义的路由都请求转发到到首页,目的是为了让前端的VUEjs架构可以刷新页面[一定要写在路由的最后,不然在其后边定义的路由也会请求转发到首页]
app.get('/*', function(req, res) {
  res.sendFile(path.resolve(path.join(__dirname, 'static') + '/index.html'))
})

app.set('port', config.PORT);

var server = http.listen(app.get('port'), function() {
  console.log('start at port:' + server.address().port);
});